package com.zuxia.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository;

import com.zuxia.dao.IStaffDao;
import com.zuxia.entity.Staff;

@Repository("staffDao")
public class StaffDao implements IStaffDao{
	@Resource(name="hibernateTemplate")
	private HibernateTemplate hibernateTemplate;
	
	@SuppressWarnings("unchecked")
	public List<Staff> findAll() {
		return (List<Staff>) hibernateTemplate.find("from Staff");
	}
	public void saveDepart(Staff staff) {
		hibernateTemplate.save(staff);
	}
	public void updateStaff(Staff staff){
		SessionFactory factory = hibernateTemplate.getSessionFactory();
		Session session = factory.getCurrentSession();
		Staff staff2=session.get(Staff.class,staff.getStaffId());
		staff2.setPosit(staff.getPosit());
		staff2.setStaffName(staff.getStaffName());
		staff2.setStaffPhone(staff.getStaffPhone());
		staff2.setStaffCarid(staff.getStaffCarid());
		staff2.setStaffSex(staff.getStaffSex());
		session.saveOrUpdate(staff2);
	}
	public void deleteStaff(Staff staff) {
		SessionFactory factory = hibernateTemplate.getSessionFactory();
		Session session = factory.getCurrentSession();
		Staff staff2=session.get(Staff.class,staff.getStaffId());
		session.delete(staff2);
	}

}
